<?php require_once(dirname(__FILE__).'/authority.php'); ?>
<?php 
	$e	= array('10'=>'登录控制面板', '11'=>'<small>帐号有误，请重新登录。</small>', '12'=>'<small>帐号权限不足，请使用管理员帐号重新登录。</small>');
?>
<?php if('chk' == $do): //check page. ?>
<?php
	$error_key = null;
	$user			= null;
	$p_username = $_POST['username'];
	$p_userpwd	= $_POST['userpwd'];
	
	$wwOptions = get_option('WapWordPressAdminOptions');
	$key = $wwOptions['ww_wap_pwd_key'];

 	$user = authority($p_username, encode($p_userpwd, $key), $error_key);
	
	$redirectUrl	= empty($user)?($_SERVER['PHP_SELF'].'?do=login&e='.$error_key):($_SERVER['PHP_SELF'].'?user='.$p_username.'&pwd='.encode($p_userpwd, $key));
?>
<wml>
	<card title="Redirecting..." ontimer="<?php echo $redirectUrl; ?>">	
		<timer name="timer1" value="3"/>
		<p align="center"><?php echo $e[$error_key]; ?></p>
		<br />
		<p align="center">如果页面没有自动跳转，请点击以下链接继续操作：</p>
		<br />
		<p align="center"><a href="<?php echo $redirectUrl; ?>">继续</a></p>
	</card>
</wml>
<?php endif; ?>
<?php if('chk' != $do):	//just login info check. ?>
<?php 
	$error_key	= $_GET['e'];
//	$error_key	= null;
	$user				= null;
	$username = trim($_GET['user']);
	$userpwd	= trim($_GET['pwd']);
	if(empty($error_key)){
	 	$user = authority($username, $userpwd, $error_key);
	}
?>
<?php if(empty($user)): ?>
<?php	$do = 'login'; ?>
<wml>
  <card title="<?php echo '控制面板 - '.$blogname; ?>">	
  	<p><?php echo $e[$error_key]; ?></p><br />
		<p>============</p>
		<p>用户名： </p>
		<p><input name="username" type="text" size="20" maxlength="60"/></p>
		<p>密码： </p>
		<p><input name="userpwd" type="password" size="20" maxlength="60"/></p>
		<do type="accept" label="登录" name="login">
			<go href="<?php echo $_SERVER['PHP_SELF'].'?do=chk'; ?>" method="post">
				<postfield name="username" value="$(username)"/>  
				<postfield name="userpwd" value="$(userpwd)"/>
			</go>
		</do>
	</card>
</wml>
<?php endif; //end of empty user. ?>
<?php endif; //end of not chk. ?>
